	
-- ***********************************************************************************************
-- GETUPDATECONFLICT Stored Procedures for the list of tables mentioned in the Initialize file
--------------------------------------------------------------------------------------------------

--TABLE NAME: CustomerContact    STORED PROCEDURE NAME: Sales.sync_sp_CustomerContact_GetUpdateConflict

use [SyncSamplesDb_ChangeTracking_Custom]

if object_id(N'Sales.sync_sp_CustomerContact_GetUpdateConflict', 'P') is not null
	drop procedure Sales.sync_sp_CustomerContact_GetUpdateConflict
GO

	create procedure Sales.sync_sp_CustomerContact_GetUpdateConflict(
        @CustomerId uniqueidentifier
		,@PhoneType nvarchar       
        )
as
	SELECT		E.CustomerId
				, E.PhoneNumber
				, E.PhoneType
				, CT.SYS_CHANGE_CONTEXT
				, CT.SYS_CHANGE_VERSION 
	FROM		[SyncSamplesDb_ChangeTracking_Custom].[Sales].[CustomerContact] AS E
	JOIN		CHANGETABLE(VERSION [SyncSamplesDb_ChangeTracking_Custom].[Sales].[CustomerContact], ([CustomerId], [PhoneType]), (@CustomerId, @PhoneType)) AS CT  
				ON E.CustomerId = CT.CustomerId
				AND E.PhoneType = CT.PhoneType

GO

-------------------------------------------END------------------------------------------------------------------
